package com.zx.crowdfunding.handler;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zx.crowdfunding.entity.vo.AddressVO;
import com.zx.crowdfunding.entity.vo.OrderProjectVO;
import com.zx.crowdfunding.entity.vo.OrderVO;
import com.zx.crowdfunding.service.api.OrderService;
import com.zx.crowdfunding.util.ResultEntity;

/**
 * 订单 - Handler - 远程接口实现
 * @author 郑雪
 * @date 2022-01-04
 */
@RestController
public class OrderProviderHandler {
	
	/**
	 * 订单Service接口
	 */
	@Autowired
	private OrderService orderService;
	
	/**
	 * 添加订单
	 * @param orderVO 订单VO对象
	 * @param memberId 会员id
	 * @return ResultEntity对象
	 */
	@RequestMapping("/save/order/vo/remote")
	public ResultEntity<String> saveOrderVORemote(@RequestBody OrderVO orderVO, @RequestParam("memberId") Integer memberId) {
		try {
			// 调用本地Service执行添加
			orderService.saveOrderVO(orderVO, memberId);
			
			// 返回结果
			return ResultEntity.successWithoutData();
								
		} catch (Exception e) {
			e.printStackTrace();
			return ResultEntity.failed(e.getMessage());
		}
	}
	
	/**
	 * 添加会员收货地址
	 * @param addressVO 收货地址VO对象
	 * @return ResultEntity对象
	 */
	@RequestMapping("/save/address/vo/remote")
	ResultEntity<String> saveAddressVORemote(@RequestBody AddressVO addressVO){
		try {
			// 调用本地Service执行添加
			orderService.saveAddressVO(addressVO);
			
			// 返回结果
			return ResultEntity.successWithoutData();
								
		} catch (Exception e) {
			e.printStackTrace();
			return ResultEntity.failed(e.getMessage());
		}
	}
	
	/**
	 * 获取会员收货地址列表
	 * @param memberId 会员id
	 * @return 携带AddressVO对象集合的ResultEntity对象
	 */
	@RequestMapping("/get/address/vo/remote/{memberId}")
	public ResultEntity<List<AddressVO>> getAddressVORemote(@PathVariable("memberId") Integer memberId){
		try {
			// 调用本地Service执行查询
			List<AddressVO> addressVOList = orderService.getAddressVOList(memberId);
			
			// 返回结果
			return ResultEntity.successWithData(addressVOList);
								
		} catch (Exception e) {
			e.printStackTrace();
			return ResultEntity.failed(e.getMessage());
		}
	}
	

	/**
	 * 获取订单项目
	 * @param returnId 项目回报id
	 * @return 携带OrderProjectVO对象的ResultEntity对象
	 */
	@RequestMapping("/get/order/project/vo/remote/{returnId}")
	public ResultEntity<OrderProjectVO> getOrderProjectVORemote(@PathVariable("returnId") Integer returnId){
		try {
			// 调用本地Service执行查询
			OrderProjectVO orderProjectVO = orderService.getOrderProjectVO(returnId);
			
			// 返回结果
			return ResultEntity.successWithData(orderProjectVO);
								
		} catch (Exception e) {
			e.printStackTrace();
			return ResultEntity.failed(e.getMessage());
		}
	}
	
}
